<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META content="text/html; charset=ISO-8859-2" http-equiv="content-type">
<meta name="robots" content="index,follow">
<META NAME="Keywords" CONTENT="resistors, resistor set searching, javascript">
<meta name="viewport" content="width=device-width, initial-scale=1">
<META NAME="Author" CONTENT="Tomasz Ostrowski">
<META name="description" content="Searching for pair or resistors giving specified equivalent resistance when connected in parallel.">  
<link rel="stylesheet" type="text/css" media="only screen and (max-width: 959px)" href="./css/mobile.css" />
<link rel="stylesheet" type="text/css" media="only screen and (min-width: 960px)" href="./css/main.css" />
<script type="text/javascript" src="./js/tree.js"></script>


<script src="./js/jquery-2.1.3.min.js"></script>
<!-- <link rel="stylesheet" type="text/css" href="./css/jquery-eu-cookie-law-popup.css"/>
<script src="./js/jquery-eu-cookie-law-popup-en.js"></script> -->

<title>Equivalent resistance resistor set search</title>  
</head>
<body class="eupopup eupopup-bottomleft eupopup-style-compact">

<div id="wrap">
<div id="header">
<div id="header_l">
  <a href="../index.htm">erma0.cn</a>
</div>
<div id="header_r"><A HREF="./par_resistors.htm" TARGET="_self"><strong>ENGLISH VERSION</strong></A><br><A HREF="./par_resistors.php?lang=pl" TARGET="_self"><strong>WERSJA POLSKA</strong></A></div>      
</div>

<a href="../bot-trap/">
  <img src="./images/pixel.gif" border="0" alt=" " width="1" height="1">
</a>
     

<script type="text/javascript">
//<!--

var E24_set = [1.0, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1]; 

function getNextResistor(resistance) {
  var order = 0;
  var mantissa = resistance * 1.000001;
  if (resistance >= 1) {
    while (mantissa >= 10) {
      mantissa /= 10;
      order++;
    } 
  } else {
    while (mantissa < 1) {
      mantissa *= 10;
      order--;
    }
  }
  var higherMantissa = E24_set[0];
  var higherMantissaFound = false; 
  for(i=0; i<E24_set.length; i++) {
    higherMantissa = E24_set[i];
    if (higherMantissa > mantissa) {
      higherMantissaFound = true;
      break;
    }    
  }
  if (higherMantissaFound == false) {
    // roll-over to 1.0
    order++;
    higherMantissa = E24_set[0];
  }
  return (higherMantissa * Math.pow(10, order));  
}

function Execute() {
  // get requested resistance in Ohms
  var resistance = parseFloat(document.frmConvert.equivalentResistance.value);
  if (isNaN(resistance)) {
    alert("Invalid resistance value!");
    return;
  }
  if (resistance <= 0) {
    alert("Negative or zero resistance value is not accepted");
    return;
  }
  
  var resArray = [];
  var R2, rEquivalent;

  var rangeMin = parseFloat(document.getElementById('selectRangeMin').value);
  var rangeMax = parseFloat(document.getElementById('selectRangeMax').value);

  // range of interest for R1: from first resistance larger than requested to 2x requested
  var R1 = getNextResistor(resistance);
  while (R1 <= 2*resistance) {
    R2 = R1;
    while (R2 < 30*resistance) {
      rEquivalent = (R1*R2)/(R1+R2);
      if (rEquivalent >= rangeMin * resistance && rEquivalent <= rangeMax * resistance) {
        resArray.push({"R1": R1, "R2": R2, "rEquivalent": rEquivalent});
      }
      // next R2
      R2 = getNextResistor(R2);
    }
    // next R1
    R1 = getNextResistor(R1);
  }

  var htmlVal = "<strong>Suggested resistor sets:</strong><br>";
  htmlVal += "<table style=\"border: thick solid; border-collapse: collapse;\">"
  htmlVal += "<tr><th style=\"border: thick solid\">R1</th><th style=\"border: thick solid\">R2</th><th style=\"border: thick solid\">Equivalent resistance</th><th style=\"border: thick solid\">Error</th></tr>";
  resArray.forEach(function(res) {
    htmlVal += "<tr><td style=\"border: thin solid\">" + parseFloat(res.R1.toPrecision(6)) + "</td><td style=\"border: thin solid\">" + parseFloat(res.R2.toPrecision(6)) + "</td><td style=\"border: thin solid\">" + res.rEquivalent.toPrecision(6) + "</td><td style=\"border: thin solid\">" + (100*(res.rEquivalent - resistance)/resistance).toFixed(2) + "%</td></th>"
  });
  htmlVal += "</table>";

  var target = document.getElementById('divOutput'); 
  target.innerHTML = htmlVal; 
}

//-->
</script>


<div id="main">

<h1>Equivalent resistance resistor set search</h1>
<p>
This script is searching for resistor set (2 resistors) that has equivalent resistance close to specified
when connected in parallel - can be used to replace resistor with value you don't have. It searches
resistors from E24 (5% tolerance) set. Direct match is ignored - purpose of this script is searching for replacement only.
</p>
<form name="frmConvert" action="">
	<p>
    Equivalent resistance needed [Ohms]:
    <input type="text" name="equivalentResistance" value="2300" style="width: 150px;">    
  </p>			    
  <p>
    Search range: from
    <select id="selectRangeMin">
      <option value="0.9">0.9</option>
      <option value="0.95">0.95</option>
      <option value="0.97">0.97</option>
      <option value="0.98" selected>0.98</option>
      <option value="0.99">0.99</option>
      <option value="1.00">1.00</option>
    </select>
    to
    <select id="selectRangeMax">
      <option value="1.00">1.00</option>
      <option value="1.01">1.01</option>
      <option value="1.02" selected>1.02</option>
      <option value="1.03">1.03</option>
      <option value="1.05">1.05</option>
      <option value="1.1">1.1</option>
    </select>
    of requested value.
  </p>			    
  <p>
    <button type=button name="btnFind"  onclick="Execute()">Find resistors</button>
	</p>
  <p>
    <div id="divOutput">
    </div>    
  </p>
</form>


</div>
<div id="sidebar">
<h3>Sitemap</h3>

<ul id="tree0" class="tree">

    <li ><a>PROJECTS</a>
    <ul>
    <li><A HREF="../programator.htm" TARGET="_self">FLASH 49F programmer</A></li> 
    </ul>
    </li>

 
    <li><a>ONLINE TOOLS</a>
    <ul>
    <li><a href="./base64.htm" TARGET="_self">Base64 -&gt; HEX</A></li>
    <li><a href="./base32.htm" TARGET="_self">Base32 -&gt; HEX</a></li>
    <li><a href="./base32hex.htm" TARGET="_self">Base32hex -&gt; HEX</a></li>
    <li><a href="./ascii.htm" TARGET="_self">ASCII -&gt; HEX</a></li>
    <li><a href="./ascii_uN.htm" TARGET="_self">ASCII -&gt; u16/u32/u64 HEX</a></li>            
    <li><a href="./hex_to_base64.htm" TARGET="_self">HEX -&gt; Base64</a></li>
    <li><a href="./text_to_base64.htm" TARGET="_self">Text -&gt; Base64</a></li>
    <li><a href="./hex_to_base32.htm" TARGET="_self">HEX -&gt; Base32</a></li>
    <li><a href="./hex_to_base32hex.htm" TARGET="_self">HEX -&gt; Base32hex</a></li>
    <li><a href="./hex_to_ascii.htm" TARGET="_self">HEX -&gt; ASCII</a></li>
    <li><a href="./hex_to_dec.htm" TARGET="_self">HEX -&gt; DEC</a></li>	
    <li><a href="./dec_to_ascii.htm" TARGET="_self">DEC -&gt; ASCII</a></li>
    <li><a href="./bin_to_32bit_hex.htm" TARGET="_self">BIN &lt;-&gt; 32-bit hex</a></li>    
    <li><a href="./md5.htm" TARGET="_self">MD5 calculator</a></li>
    <li><a href="./sha1.htm" TARGET="_self">SHA1 calculator</a></li>    
    <li><a href="./regexp.htm" TARGET="_self">Regular exp.</a></li>
    <li><a href="./cpp_text_escape.htm" TARGET="_self">Text -&gt; Cpp</a></li>
    <li><a href="./cpp_unescape.htm" TARGET="_self">Cpp -&gt; text</a></li>
    <li><a href="./pascal_escape.htm" TARGET="_self">Text -&gt; Pascal</a></li>        
    <li><a href="./hex_to_file.htm" TARGET="_self">HEX -&gt; file</a></li>
    <li><a href="./file_to_hex.htm" TARGET="_self">File -&gt; HEX</a></li>
    <li><a href="./file_to_base64.htm" TARGET="_self">File -&gt; Base64</a></li>    
    <li><a href="./html_list_gen.htm" TARGET="_self">Text -&gt; HTML ul</a></li>
    <li><a href="./crc8.htm" TARGET="_self">CRC8</a></li>
    <li><a href="./wave_gen.htm" TARGET="_self">WAVE generator</a></li>
    <li><a href="./bin_decoder.htm" TARGET="_self">Bin decoder</a></li>
    <li><a href="./rc4.htm" TARGET="_self">RC4</a></li>          
    <li><a href="./xor.htm" TARGET="_self">XOR</a></li>
    <li><a href="./inv.htm" TARGET="_self">Inverting bits</a></li>
    <li><a href="./par_resistors.htm" TARGET="_self">Par. resistors search</a></li>
    <li><a href="./unique_str.htm" TARGET="_self">Deduplicate / sort</a></li>        
    <li><a href="./base64_to_PEM.htm" TARGET="_self">Base64 -&gt; PEM</a></li>
    <li><a href="./PEM_to_base64.htm" TARGET="_self">PEM -&gt; base64</a></li>
    <li><a href="./diskstats.htm" TARGET="_self">/proc/diskstats</a></li>    
    </ul>
    </li> 


    <li><A HREF="../contact2.htm" TARGET="_self">Contact</A></li></ul>
<script type="text/javascript">
//<!--
new tree("tree0");
//-->
</script>

<br>  
<br>  
<br>  





  <br>    

        
    
</div>


<div id="footer">




  
</div>


<br>
<div id="footer2"><p>      
            <!-- <font size="-2">&nbsp;"Cookie monsters": 5583818&nbsp;&nbsp;&nbsp;&nbsp;Parse time:&nbsp;0.000 s</font> -->

  </p>
	</div>
</div>
</body>
</html>

